﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Domain.LogDomain;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;
using Zocono.WCS.Infrastructure.ApllicationDto.FxModel;
using Zocono.WCS.Infrastructure.ApllicationDto.WCSTaskDto;

namespace Zocono.WCS.WMSApiDomain.WebApi
{
    public class WCSMessageWithWMSApi
    {

        private static IInterfaceLogInfoService _IIterfaceLogInfoService;
        private static ILogUtil _LogUtil;

        public WCSMessageWithWMSApi(IInterfaceLogInfoService iterfaceLogInfoService, ILogUtil logUtil)
        {
            _IIterfaceLogInfoService = iterfaceLogInfoService;
            _LogUtil = logUtil;
        }

        /// <summary>
        /// WCS申请巷道
        /// </summary>
        /// <param name="containerBarcode">托盘码，容器码</param>
        /// <param name="equipment">设备号</param>
        /// <returns></returns>
        public static async Task<HeaderResult<WmsTaskInfoDto>> WCSCreatUploadWarehouseWMSTaskAsync(string containerBarcode, string equipment)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = "托盘码：" + containerBarcode + "  设备号：" + equipment;
                interfaceLogInfo.ActionName = "WCSCreatUploadWarehouseWMSTaskAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSCreatUploadWarehouseWMSTask;
                interfaceLogInfo.Description = "类型：WCS向WMS申请巷道托盘码";

                HeaderResult<WmsTaskInfoDto> headerResult = await SimpleApiClient.GetAsync<HeaderResult<WmsTaskInfoDto>>(Parameters.WCSCreatUploadWarehouseWMSTask, new { containerBarcode = containerBarcode.Trim(), equipment = equipment });
                //var headerResult = await SimpleApiClient.GetAsync<WmsTaskInfoDto>(Parameters.WCSCreatUploadWarehouseWMSTask, new { containerBarcode = "FABA919270", equipment = equipment });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {

                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }


        /// <summary>
        /// WCS检测数量到扫码
        /// </summary>
        /// <param name="containerBarcode">托盘码，容器码</param>
        /// <param name="equipmentCode">设备号</param>
        /// <returns></returns>
        public static async Task<WmsTaskInfoDto> WCSCreatCheckCountWMSTaskAsync(string containerBarcode, string equipmentCode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = "托盘码：" + containerBarcode + "  设备号：" + equipmentCode;
                interfaceLogInfo.ActionName = "WCSCreatCheckCountWMSTaskAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSCreatUploadWarehouseWMSTask;
                interfaceLogInfo.Description = "类型：WCS向WMS请求检测数量任务";
                WmsTaskInfoDto headerResult = await SimpleApiClient.GetAsync<WmsTaskInfoDto>(Parameters.WCSCreatUploadWarehouseWMSTask, new { containerBarcode = containerBarcode, equipmentCode = equipmentCode });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 校验电池数量
        /// </summary>
        /// <param name="containerBarcode"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public static async Task<HeaderResult<bool>> WCSGetBatteryCountAsync(string containerBarcode, int num, string equipmentcode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = "托盘码：" + containerBarcode + "  设备号：" + equipmentcode.ToString() + "  数量：" + num.ToString();
                interfaceLogInfo.ActionName = "WCSGetBatteryCountAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WMSGetWMSCCDCheckResult;
                interfaceLogInfo.Description = $"类型：WCS校验电池数量发送给WMS";
                HeaderResult<bool> result = await SimpleApiClient.GetAsync<HeaderResult<bool>>(Parameters.WMSGetWMSCCDCheckResult, new { containercode = containerBarcode, num = num, equipment = equipmentcode });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(result); ;
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return result;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 获取目标位置
        /// </summary>
        /// <param name="containerBarcode"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public static async Task<long> WCSGetDoToEquimentAsync(string containerBarcode)
        {
            try
            {
                var flag = await SimpleApiClient.GetAsync<long>(Parameters.WMSGetWMSCCDCheckResult, new { palletecode = containerBarcode });
                return flag;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// WCS申请货位
        /// </summary>
        /// <param name="taskCode"></param>
        /// <param name="equipmentCode"></param>
        /// <param name="containerCode"></param>
        /// <param name="colum"></param>
        /// <returns></returns>
        public static async Task<HeaderResult<AllotLocationOutputDto>> WCSGetAllotLocatonAsync(long taskCode, string equipmentCode, string containerCode, string colum)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containerCode}；任务号：{taskCode}；设备号：{equipmentCode}";
                interfaceLogInfo.ActionName = "WCSGetAllotLocatonAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSGetAllotLocaton;
                interfaceLogInfo.Description = $"类型：WCS申请货位";
                HeaderResult<AllotLocationOutputDto> headerResult = await SimpleApiClient.GetAsync<HeaderResult<AllotLocationOutputDto>>(Parameters.WCSGetAllotLocaton, new { taskCode = taskCode, equipmentCode = equipmentCode, containerCode = containerCode.Trim(), colum = colum });
                //if (headerResult.IsSucceed)
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                var msg = ex.Message.Split("at").First().Split("System.Exception:");
                interfaceLogInfo.InterfaceResult = msg[1];
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 卸载占位重分配
        /// </summary>
        /// <param name="taskCode"></param>
        /// <param name="locationCode"></param>
        /// <returns></returns>
        public static async Task<AllotLocationOutputDto> WCSGetReAllotLocatonAsync(long taskCode, string locationCode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = $"任务号：{taskCode}；货位号：{locationCode}";
                interfaceLogInfo.ActionName = "WCSGetReAllotLocatonAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSGetReAllotLocaton;
                interfaceLogInfo.Description = $"类型：卸载占位重分配";
                AllotLocationOutputDto headerResult = await SimpleApiClient.GetAsync<AllotLocationOutputDto>(Parameters.WCSGetReAllotLocaton, new { taskCode = taskCode, locationCode = locationCode });
                //LogWriter.WriteLogWMSApiJson($"类型：卸载占位重分配返回：货位号：{headerResult.LocationCode}");
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 取空异常接口
        /// </summary>
        /// <param name="taskCode"></param>
        /// <param name="locationCode"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public static async Task<bool> WCSNoticeErrorTaskProcessStateAsync(long taskCode, string locationCode, int state)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = $"任务号：{taskCode}；货位号：{locationCode}；状态：{state}";
                interfaceLogInfo.ActionName = "WCSNoticeErrorTaskProcessStateAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSNoticeErrorTaskProcessState;
                interfaceLogInfo.Description = $"类型：取空异常接口";
                bool headerResult = await SimpleApiClient.GetAsync<bool>(Parameters.WCSNoticeErrorTaskProcessState, new { taskCode = taskCode, locationCode = locationCode, state = state });
                //LogWriter.WriteLogWMSApiJson($"类型：WCS校验电池数量返回：结果{headerResult}");
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 任务自动完成
        /// </summary>
        /// <param name="taskCode"></param>
        /// <returns></returns>
        public static async Task<HeaderResult<bool>> WCSNoticeTaskAutoCompleteAsync(long taskCode, string containercode, string equipment)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = $"任务号：{taskCode}；托盘码{containercode}；目标设备：{equipment}";
                interfaceLogInfo.ActionName = "WCSNoticeTaskAutoCompleteAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSNoticeTaskAutoComplete;
                interfaceLogInfo.Description = $"类型：任务自动完成";
                HeaderResult<bool> headerResult = await SimpleApiClient.GetAsync<HeaderResult<bool>>(Parameters.WCSNoticeTaskAutoComplete, new { taskCode = taskCode, containercode = containercode, equipment = equipment });
                interfaceLogInfo.InterfaceResult = headerResult.Message;
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                interfaceLogInfo.InterfaceResult = $"申请完成任务失败{ex.Message}";
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 任务自动完成
        /// </summary>
        /// <param name="taskCode"></param>
        /// <returns></returns>
        public static async Task<bool> WCSNoticeTaskAutoCompleteAsync(long taskCode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = $"任务号：{taskCode}；";
                interfaceLogInfo.ActionName = "WCSNoticeTaskAutoCompleteAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSNoticeTaskAutoComplete;
                interfaceLogInfo.Description = $"类型：任务自动完成";
                bool headerResult = await SimpleApiClient.GetAsync<bool>(Parameters.WCSNoticeTaskAutoComplete, new { taskCode = taskCode });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                interfaceLogInfo.InterfaceResult = "申请完成任务失败";
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }


        /// <summary>
        /// 获取下架（越库、移库、倒库）任务接口 (弃用)
        /// </summary>
        /// <returns></returns>
        public static async Task<List<WmsTaskInfoDto>> WCSGetWMSInitialWorkTaskAsync(IInterfaceLogInfoService _iterfaceLogInfoService)
        {
            _IIterfaceLogInfoService = _iterfaceLogInfoService;
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = "无";
                interfaceLogInfo.ActionName = "WCSGetWMSInitialWorkTaskAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSGetWMSInitialWorkTask;
                interfaceLogInfo.Description = " 获取下架（越库、移库、倒库）任务接口 (弃用)";
                List<WmsTaskInfoDto> headerResult = await SimpleApiClient.GetAsync<List<WmsTaskInfoDto>>(Parameters.WCSGetWMSInitialWorkTask);
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null && headerResult.Count != 0)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                //if (ex.Message.Contains("at")&& ex.Message.Contains("System.Exception:"))
                //{

                //    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                //    interfaceLogInfo.InterfaceResult = msg[1];

                //}
                //interfaceLogInfo.IsSuccess = false;
                //if (_IIterfaceLogInfoService != null)
                //    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 到达DO台释放货位
        /// </summary>
        /// <param name="taskCode"></param>
        /// <returns></returns>
        public static async Task<HeaderResult<bool>> WCSNoticePalltetArriveDoEquipmentAsync(long taskCode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = $"任务号：{taskCode}；";
                interfaceLogInfo.ActionName = "WCSNoticePalltetArriveDoEquipmentAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSNoticePalltetArriveDoEquipment;
                interfaceLogInfo.Description = $"类型：到达DO台释放货位";
                HeaderResult<bool> headerResult = await SimpleApiClient.GetAsync<HeaderResult<bool>>(Parameters.WCSNoticePalltetArriveDoEquipment, new { taskCode = taskCode });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        ///  扫码组盘接口(整盘数据)
        /// </summary>
        /// <param name="wCSCombinePalletInfoDto"></param>
        /// <returns></returns>
        public static async Task<bool> WCSAddComPalletAsync(WCSCombinePalletInfoDto wCSCombinePalletInfoDto)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = $"组盘数据：{JsonConvert.SerializeObject(wCSCombinePalletInfoDto)}；";
                interfaceLogInfo.ActionName = "WCSAddComPalletAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSAddComPallet;
                interfaceLogInfo.Description = $"类型：扫码组盘接口(整盘数据)";
                HeaderResult<bool> headerResult = await SimpleApiClient.PostAsync<HeaderResult<bool>>(Parameters.WCSAddComPallet, wCSCombinePalletInfoDto);
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult.IsSucceed;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {
                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// WCS获取WMS手动完成，取消的作业
        /// </summary>
        /// <returns></returns>
        public static async Task<List<WmsTaskInfoDto>> WCSGetWMSManualFinishORCancelWorkTaskAsync()
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = "无";
                interfaceLogInfo.ActionName = "WCSGetWMSManualFinishORCancelWorkTaskAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSGetWMSManualFinishORCancelWorkTask;
                interfaceLogInfo.Description = $"类型：WCS获取WMS手动完成，取消的作业发送;";
                List<WmsTaskInfoDto> headerResult = await SimpleApiClient.GetAsync<List<WmsTaskInfoDto>>(Parameters.WCSGetWMSManualFinishORCancelWorkTask);
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                //if (_IIterfaceLogInfoService != null)
                //    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                //if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                //{

                //    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                //    interfaceLogInfo.InterfaceResult = msg[1];

                //}
                //if (_IIterfaceLogInfoService != null )
                //{
                //    interfaceLogInfo.IsSuccess = false;
                //    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                //}
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// WCS更新WMS作业状态和执行状态
        /// </summary>
        /// <param name="taskcode"></param>
        /// <param name="taskstate"></param>
        /// <param name="processtaskstate"></param>
        /// <returns></returns>
        public static async Task<bool> WCSUpdateWMStaskStateAndProcessTaskStateAsync(long taskcode, int? taskstate = null, int? processtaskstate = null)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = $"任务号：{taskcode}；processtaskstate：{processtaskstate}；任务状态：{taskstate}";
                interfaceLogInfo.ActionName = "WCSUpdateWMStaskStateAndProcessTaskStateAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSUpdateWMStaskStateAndProcessTaskState;
                interfaceLogInfo.Description = $"类型：WCS更新WMS作业状态和执行状态发送";
                bool flag = await SimpleApiClient.GetAsync<bool>(Parameters.WCSUpdateWMStaskStateAndProcessTaskState, new { taskcode = taskcode, taskstate = taskstate, processtaskstate = processtaskstate });
                interfaceLogInfo.InterfaceResult = flag.ToString();
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return flag;
            }
            catch (Exception ex)
            {
                interfaceLogInfo.InterfaceResult = "申请WMS异常";

                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return false;
            }
        }

        /// <summary>
        /// WCS 根据托盘号获取是否是 1空盘，2满盘  ,3异常盘  
        /// </summary>
        /// <param name="containerBarcode"></param>
        /// <returns></returns>
        public static async Task<int> WMSCheckExistPalletbatteryCombineInfoAsync(string containerBarcode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containerBarcode}";
                interfaceLogInfo.ActionName = "WCSUpdateWMStaskStateAndProcessTaskStateAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSUpdateWMStaskStateAndProcessTaskState;
                interfaceLogInfo.Description = "类型：WCS 根据托盘号获取是否是 1空盘，2满盘  ,3异常盘";
                int flag = await SimpleApiClient.GetAsync<int>(Parameters.WMSCheckExistPalletbatteryCombineInfo, new { containerBarcode = containerBarcode });
                interfaceLogInfo.InterfaceResult = flag.ToString();
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return flag;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 托盘解绑
        /// </summary>
        /// <param name="containerCode"></param>
        /// <param name="equipmentCode"></param>
        /// <param name="taskCode"></param>
        /// <returns></returns>
        public static async Task<HeaderResult<bool>> UnbandingContainerAsync(string containerCode, string equipmentCode, long taskCode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<bool> headerResult = new HeaderResult<bool>();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containerCode}；设备号{equipmentCode}；任务号{taskCode}";
                interfaceLogInfo.ActionName = "UnBandingContainerAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.UnbandingContainer;
                interfaceLogInfo.Description = "类型：托盘解绑";
                //headerResult = await SimpleApiClient.PostAsync<HeaderResult<bool>>(Parameters.UnbandingContainer, new { containercode = containerCode, equipment = equipmentCode, taskcode = taskCode });
                //由post请求改为get请求
                headerResult = await SimpleApiClient.GetAsync<HeaderResult<bool>>(Parameters.UnbandingContainer, new { containercode = containerCode, equipment = equipmentCode, taskcode = taskCode });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch
            {
                interfaceLogInfo.InterfaceResult = "调用接口异常";
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                headerResult.IsSucceed = false;
                headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }
        /// <summary>
        /// 电池托盘类型
        /// </summary>
        /// <param name="palletBarcode"></param>
        /// <returns></returns>
        public static async Task<HeaderResult<BatteryCountAndTypeDto>> WCSGetBatteryInfoByContainerCodeAsync(WCSQueryCombinePalletDto palletBarcode)
        {
            InterfaceLogInfo interfaceLogInfo = new();
            HeaderResult<BatteryCountAndTypeDto> headerResult = new();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{palletBarcode.PalletCode}";
                interfaceLogInfo.ActionName = "WCSGetBatteryInfoByContainerCodeAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSGetBatteryInfoByContainerCode;
                interfaceLogInfo.Description = "类型：获取电池类型";
              //  headerResult = await SimpleApiClient.PostAsync<HeaderResult<BatteryCountAndTypeInfoDto>>(Parameters.WCSGetBatteryInfoByContainerCode, new { palletCode = palletBarcode });//
                headerResult = await SimpleApiClient.PostAsync<HeaderResult<BatteryCountAndTypeDto>>(Parameters.WCSGetBatteryInfoByContainerCode, new { palletCode = palletBarcode.PalletCode });
         
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch
            {
                interfaceLogInfo.InterfaceResult = "调用接口异常";
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                headerResult.IsSucceed = false;
                headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }




        /// <summary>
        /// 空盘回库校验
        /// </summary>
        /// <param name="containerCode"></param>
        /// <param name="equipmentCode"></param>
        /// <returns></returns>
        public static async Task<HeaderResult<bool>> EmptyContainerReturnAsync(string containerCode, string equipmentCode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<bool> headerResult = new HeaderResult<bool>();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containerCode}；设备号{equipmentCode}；";
                interfaceLogInfo.ActionName = "EmptyContainerReturn";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.EmptyContainerReturn;
                interfaceLogInfo.Description = "类型：空盘回库检测";
                headerResult = await SimpleApiClient.GetAsync<HeaderResult<bool>>(Parameters.EmptyContainerReturn, new { containercode = containerCode, equipment = equipmentCode });
                interfaceLogInfo.InterfaceResult = JsonHelper.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch(Exception ex)
            {
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = "空托回库校验异常：" + msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                headerResult.IsSucceed = false;
                headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }


        /// <summary>
        /// PLC→WCS→WMS申请盘点模式
        /// </summary>
        /// <param name="PalletBarcode">托盘码</param>
        /// <param name="EquipmentCode">设备号</param>
        /// <returns></returns>
        public static async Task<HeaderResult<int>> WCSGetCheckModelAsync(string PalletBarcode, string EquipmentCode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();

            //PLC→WCS→WMS申请盘点模式    
            HeaderResult<int> AutomaticOrManual = new HeaderResult<int>();

            interfaceLogInfo.InterfacePara = $"托盘码：{PalletBarcode}，设备号：{EquipmentCode}";
            interfaceLogInfo.ActionName = "WCSGetCheckModelAsync";
            interfaceLogInfo.StartTime = DateTime.Now;
            interfaceLogInfo.InterfaceUrl = Parameters.WCSGetCheckModel;
            interfaceLogInfo.Description = "类型：WCS向WMS申请盘点模式";
            try
            {
                //调用WMS提供的接口，向WMS询问是自动扫码，还是人工PDA扫码，返回51表示自动（粗盘点），52人工（细盘点）;

                AutomaticOrManual = await SimpleApiClient.GetAsync<HeaderResult<int>>(Parameters.WCSGetCheckModel, new { containercode = PalletBarcode, plccode = EquipmentCode });

                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(AutomaticOrManual);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;

                //await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return AutomaticOrManual;
            }
            catch (Exception ex)
            {
                interfaceLogInfo.InterfaceResult = $"调用接口异常：{ex.Message}";
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = false;
                await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);

                AutomaticOrManual.Result = 0;
                return AutomaticOrManual;
            }


        }

        /// <summary>
        /// 向WMS上传盘点托盘信息
        /// </summary>
        /// <param name="PalletBarcode">托盘码</param>
        /// <param name="EquipmentCode">设备号</param>
        /// <param name="BatteryCode">电池条码</param>
        /// <param name="BatteryIndex">电芯位置</param>
        /// <returns></returns>
        public static async Task<HeaderResult<int>> WCSGetCheckDestinationAsync(string PalletBarcode, string EquipmentCode, string BatteryCode, int BatteryIndex)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();


            /*向WMS上传数据
             * 参数
               containercode：plc扫码枪读出的托盘编码
               plccode：协议里面的plc设备编号
               batterycode:电芯条码
               position：电芯位置

               WMS产生任务给WCS----->WCS给到PLC(因为以前WMS下发WCS任务，WCS有拉取方法这里不在做返回结果处理)
            */
            interfaceLogInfo.InterfacePara = $"托盘码:{PalletBarcode},设备号:{EquipmentCode},电池条码:{BatteryCode},电芯位置:{BatteryIndex}";
            interfaceLogInfo.ActionName = "WCSGetCheckDestinationAsync";
            interfaceLogInfo.StartTime = DateTime.Now;
            interfaceLogInfo.InterfaceUrl = Parameters.WCSGetCheckDestination;
            interfaceLogInfo.Description = "类型：向WMS上传数据";

            HeaderResult<int> uploaddataResult = new HeaderResult<int>();

            try
            {
                uploaddataResult = await SimpleApiClient.GetAsync<HeaderResult<int>>(Parameters.WCSGetCheckDestination, new { containercode = PalletBarcode, plccode = EquipmentCode, batterycode = BatteryCode, position = BatteryIndex });

                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(uploaddataResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;

                await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return uploaddataResult;
            }
            catch (Exception ex)
            {
                interfaceLogInfo.InterfaceResult = $"调用接口异常：{ex.Message}";
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = false;

                await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);

                uploaddataResult.Result = 0;
                return uploaddataResult;
            }



        }


        /// <summary>
        ///盘点取料判断
        /// </summary>
        /// <param name="EquipmentCode">设备号</param>
        /// <param name="StartlinetoPC">行</param>
        /// <param name="StartcolumntoPC">列</param>
        /// <param name="StartlayertoPC">层</param>
        /// <returns>返回结果 57=自动清楚 58=异常</returns>
        public static async Task<HeaderResult<int>> WCSGetErrorResultAsync(string EquipmentCode, int StartlinetoPC, int StartcolumntoPC, int StartlayertoPC)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();

            /*上报WMS
             *  返回结果 57=自动清楚 58=异常
             *  参数
                plccode：协议里面的plc设备编号
                row:行
                col：列
                layer：层
           */
            HeaderResult<int> ClearOrAlarm = new HeaderResult<int>();

            interfaceLogInfo.InterfacePara = $"设备号：{EquipmentCode}，行：{StartlinetoPC}，列：{StartcolumntoPC}，层：{StartlayertoPC}";
            interfaceLogInfo.ActionName = "WCSGetErrorResultAsync";
            interfaceLogInfo.StartTime = DateTime.Now;
            interfaceLogInfo.InterfaceUrl = Parameters.WCSGetErrorResult;
            interfaceLogInfo.Description = "类型：上报WMS设备号，行，列，层";

            try
            {
                ClearOrAlarm = await SimpleApiClient.GetAsync<HeaderResult<int>>(Parameters.WCSGetErrorResult, new { plccode = EquipmentCode, row = StartlinetoPC, col = StartcolumntoPC, layer = StartlayertoPC });

                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(ClearOrAlarm);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;

                //await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return ClearOrAlarm;
            }
            catch (Exception ex)
            {
                interfaceLogInfo.InterfaceResult = $"调用接口异常：{ex.Message}";
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = false;

                await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);

                ClearOrAlarm.Result = 0;
                return ClearOrAlarm;
            }

        }



        /// <summary>
        /// 回滚流程逻辑  一楼环线130187扫码确认 未分配打包台 回滚至 130067
        /// </summary>
        /// <param name="containerBarcode">托盘码，容器码</param>
        /// <param name="equipment">设备号</param>
        /// <returns></returns>
        public static async Task<HeaderResult<WmsTaskInfoDto>> WCSGetRollbackTaskAsync(string containerBarcode, string equipment)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            try
            {
                interfaceLogInfo.InterfacePara = "托盘码：" + containerBarcode + "  设备号：" + equipment;
                interfaceLogInfo.ActionName = "WCSGetRollbackTaskAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSGetRollbackTaskAsync;
                interfaceLogInfo.Description = "类型：一楼环线回滚任务";

                HeaderResult<WmsTaskInfoDto> headerResult = await SimpleApiClient.GetAsync<HeaderResult<WmsTaskInfoDto>>(Parameters.WCSGetRollbackTaskAsync, new { containerBarcode = containerBarcode.Trim(), equipment = equipment.Trim() });
                //var headerResult = await SimpleApiClient.GetAsync<WmsTaskInfoDto>(Parameters.WCSCreatUploadWarehouseWMSTask, new { containerBarcode = "FABA919270", equipment = equipment });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                if (_LogUtil != null)
                {
                    _LogUtil.Error($"一楼环线申请回滚任务报错， ex = {ex.Message}");
                    _LogUtil.Error($"一楼环线申请回滚任务报错， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = "环线进入打包台调用接口异常：" + msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                throw new Exception(ex.Message.ToString());
            }
        }



        /// <summary>
        /// 进入打包台，脱离环形线  一楼分配到打包台后
        /// </summary>
        /// <param name="containerCode"></param>
        /// <param name="equipmentCode"></param>
        /// <returns></returns>
        public static async Task<HeaderResult<bool>> TrayOutRingLineAsync(string containerCode, string equipmentCode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<bool> headerResult = new HeaderResult<bool>();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containerCode}；设备号{equipmentCode}；";
                interfaceLogInfo.ActionName = "TrayOutRingLineAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.TrayOutRingLineAsync;
                interfaceLogInfo.Description = "类型：一楼环线进入打包台";
                headerResult = await SimpleApiClient.GetAsync<HeaderResult<bool>>(Parameters.TrayOutRingLineAsync, new { containercode = containerCode.Trim(), equipment = equipmentCode.Trim() });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch(Exception ex)
            {

                if (_LogUtil != null)
                {
                    _LogUtil.Error($"一楼环线申请回滚任务报错， ex = {ex.Message}");
                    _LogUtil.Error($"一楼环线申请回滚任务报错， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                headerResult.IsSucceed = false;
                headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }

        /// <summary>
        /// 拉取恒翼能设备信息
        /// </summary>
        /// <returns></returns>
        public static async Task<HeaderResult<List<HynReturnState>>> GetHynnStateAsync()
        {

            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<List<HynReturnState>> headerResult = new HeaderResult<List<HynReturnState>>();
            try
            {
                interfaceLogInfo.InterfacePara = $"拉取恒翼能设备状态信息；";
                interfaceLogInfo.ActionName = "GetHynnStateAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.GetHynnStateAsync;
                interfaceLogInfo.Description = "拉取恒翼能设备";
                headerResult = await SimpleApiClient.GetAsync<HeaderResult<List<HynReturnState>>>(Parameters.TrayOutRingLineAsync, new { });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {

                if (_LogUtil != null)
                {
                    _LogUtil.Error($"拉取恒翼能设备状态信息， ex = {ex.Message}");
                    _LogUtil.Error($"拉取恒翼能设备状态信息， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                headerResult.IsSucceed = false;
                headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }
        
        /// <summary>
        /// 到达分选机上报完成
        /// </summary>
        /// <returns></returns>
        public static async Task<HeaderResult<int>> WCSNoticePalltetArriveFenxuanEquipmentAsync(long taskCode, string containercode, string equipment)
        {

            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<int> headerResult = new HeaderResult<int>();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containercode}；设备号{equipment}；";
                interfaceLogInfo.ActionName = "WCSNoticePalltetArriveFenxuanEquipmentAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.GetGradeAsync;
                interfaceLogInfo.Description = "到达分选机上报完成";
                headerResult = await SimpleApiClient.GetAsync<HeaderResult<int>>(Parameters.WCSNoticePalltetArriveFenxuanEquipmentAsync, new {taskCode, containercode = containercode.Trim(), equipment = equipment.Trim() });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {

                if (_LogUtil != null)
                {
                    _LogUtil.Error($"到达分选机上报完成， ex = {ex.Message}");
                    _LogUtil.Error($"到达分选机上报完成， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                headerResult.IsSucceed = false;
                headerResult.Message = "到达分选机上报完成调用接口异常";
                return headerResult;
            }
        }

        /// <summary>
        /// 分选机获取托盘的信息
        /// </summary>
        /// <returns></returns>
        public static async Task<HeaderResult<ReturnContainer>> GetContainerMsgAsync(string containerCode, string equipmentCode)
        {

            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<ReturnContainer> headerResult = new HeaderResult<ReturnContainer>();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containerCode}；设备号{equipmentCode}；";
                interfaceLogInfo.ActionName = "GetContainerMsgAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.GetContainerMsgAsync;
                interfaceLogInfo.Description = "分选机调用WMS";
                headerResult = await SimpleApiClient.GetAsync<HeaderResult<ReturnContainer>>(Parameters.GetContainerMsgAsync, new { containercode = containerCode.Trim(), equipment = equipmentCode.Trim() });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {

                if (_LogUtil != null)
                {
                    _LogUtil.Error($"分选机获取托盘的信息， ex = {ex.Message}");
                    _LogUtil.Error($"分选机获取托盘的信息， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                headerResult.IsSucceed = false;
                headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }

        /// <summary>
        /// 获取电芯等级
        /// </summary>
        /// <returns></returns>
        public static async Task<Result> GetGradeAsync(string containerCode, string equipmentCode)
        {

            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            Result headerResult = new Result();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containerCode}；设备号{equipmentCode}；";
                interfaceLogInfo.ActionName = "GetContainerMsgAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.GetGradeAsync;
                interfaceLogInfo.Description = "调用Wtm分选机";
                headerResult = await SimpleApiClient.PostAsync<Result>(Parameters.GetGradeAsync, new { ContainerBarcode = containerCode.Trim(), EquipmentCode = equipmentCode.Trim() });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {

                if (_LogUtil != null)
                {
                    _LogUtil.Error($"获取电芯等级， ex = {ex.Message}");
                    _LogUtil.Error($"获取电芯等级， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                //headerResult.IsSucceed = false;
                //headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }


        
        /// <summary>
        /// 上报电芯分档结果
        /// </summary>
        /// <returns></returns>
        public static async Task<Result> PostMesResultAsync(List<BatteryUpDataDto> items,IInterfaceLogInfoService iterfaceLogInfoService)
        {

            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            Result headerResult = new Result();
            try
            {
                interfaceLogInfo.InterfacePara = $"上传分选结果：{JsonConvert.SerializeObject(items)}";
                interfaceLogInfo.ActionName = "PostMesResultAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.PostMesResultAsync;
                interfaceLogInfo.Description = "调用Wtm分选机上传分选结果";
                headerResult = await SimpleApiClient.PostAsync<Result>(Parameters.PostMesResultAsync, items);
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                //_LogUtil.Debug($"分选机获取托盘的信息日志前， ex = {JsonConvert.SerializeObject(interfaceLogInfo)}");
                if (iterfaceLogInfoService != null)
                    await iterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                //_LogUtil.Debug($"分选机获取托盘的信息日志后， ex = {JsonConvert.SerializeObject(interfaceLogInfo)}");
                return headerResult;
            }
            catch (Exception ex)
            {

                if (_LogUtil != null)
                {
                    _LogUtil.Error($"上传分选结果， ex = {ex.Message}");
                    _LogUtil.Error($"上传分选结果， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                //headerResult.IsSucceed = false;
                //headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }

        /// <summary>
        /// 分选机NG挑选剩余电芯上报
        /// </summary>
        /// <param name="wcsOkResultUpload"></param>
        /// <returns></returns>
        public static async Task<HeaderResult<bool>> WCSUploadNgResultAsync(WcsOkResultUploadInfo wcsOkResultUpload)
        {
            
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<bool> headerResult = new HeaderResult<bool>();
            try
            {
                interfaceLogInfo.InterfacePara = $"分选机NG挑选剩余电芯上报托盘码：{wcsOkResultUpload.ContainerCode}；设备号{wcsOkResultUpload.EquipmentCode}；";
                interfaceLogInfo.ActionName = "WCSUploadNgResultAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSUploadNgResultAsync;
                interfaceLogInfo.Description = "分选机NG挑选剩余电芯上报";
                headerResult = await SimpleApiClient.PostAsync<HeaderResult<bool>>(Parameters.WCSUploadNgResultAsync, wcsOkResultUpload);
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                if (_LogUtil != null)
                {
                    _LogUtil.Error($"分选机NG挑选剩余电芯上报， ex = {ex.Message}");
                    _LogUtil.Error($"分选机NG挑选剩余电芯上报， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {
                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];
                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                //headerResult.IsSucceed = false;
                //headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }

        /// <summary>
        /// 拉取电芯挡位信息后更新电芯挡位信息
        /// </summary>
        /// <param name="wcsOkResultUpload"></param>
        /// <returns></returns>
        public static async Task<HeaderResult<bool>> WCSUpdateBatteryGearInfoAsync(WcsSelectResultUploadInfo wcsSelectResultUpload)
        {
            
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<bool> headerResult = new HeaderResult<bool>();
            try
            {
                interfaceLogInfo.InterfacePara = $"拉取电芯挡位信息后更新电芯挡位信息：{wcsSelectResultUpload.ContainerCode}；设备号{wcsSelectResultUpload.EquipmentCode}；";
                interfaceLogInfo.ActionName = "WCSUpdateBatteryGearInfoAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSUpdateBatteryGearInfoAsync;
                interfaceLogInfo.Description = "拉取电芯挡位信息后更新电芯挡位信息";
                headerResult = await SimpleApiClient.PostAsync<HeaderResult<bool>>(Parameters.WCSUpdateBatteryGearInfoAsync, wcsSelectResultUpload);
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {
                if (_LogUtil != null)
                {
                    _LogUtil.Error($"拉取电芯挡位信息后更新电芯挡位信息， ex = {ex.Message}");
                    _LogUtil.Error($"拉取电芯挡位信息后更新电芯挡位信息， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {
                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];
                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                //headerResult.IsSucceed = false;
                //headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }

        /// <summary>
        /// 跳过流程实例去下一个流程实例节点
        /// </summary>
        /// <param name="containerCode"></param>
        /// <param name="equipmentCode"></param>
        /// <returns></returns>
        public static async Task<HeaderResult<bool>> ExtentOutThisProcessAsync(string containerCode, string equipmentCode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<bool> headerResult = new HeaderResult<bool>();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containerCode}；设备号{equipmentCode}；";
                interfaceLogInfo.ActionName = "ExtentOutThisProcessAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.ExtentOutThisProcessAsync;
                interfaceLogInfo.Description = "类型：跳过流程实例去下一个流程实例节点";
                headerResult = await SimpleApiClient.GetAsync<HeaderResult<bool>>(Parameters.ExtentOutThisProcessAsync, new { containercode = containerCode.Trim(), equipment = equipmentCode.Trim() });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch(Exception ex)
            {

                if (_LogUtil != null)
                {
                    _LogUtil.Error($"跳过流程实例去下一个流程实例节点任务报错， ex = {ex.Message}");
                    _LogUtil.Error($"跳过流程实例去下一个流程实例节点任务报错， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                headerResult.IsSucceed = false;
                headerResult.Message = "跳过流程实例去下一个流程实例节点调用接口异常";
                return headerResult;
            }
        }


        /// <summary>
        /// 获取托盘空盘实盘类型
        /// </summary>
        /// <param name="containercode"></param>
        /// <param name="equipment"></param>
        /// <returns>1=空盘 2=半托 3=满盘 -1=报错或者无托盘信息</returns>
        public static async Task<HeaderResult<int>> WCSGetPallentTypeAsync(string containerCode, string equipmentCode)
        {
            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<int> headerResult = new HeaderResult<int>();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containerCode}；设备号{equipmentCode}；";
                interfaceLogInfo.ActionName = "WCSGetPallentTypeAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.WCSGetPallentTypeAsync;
                interfaceLogInfo.Description = "获取托盘空盘实盘类型";
                headerResult = await SimpleApiClient.GetAsync<HeaderResult<int>>(Parameters.WCSGetPallentTypeAsync, new { containercode = containerCode.Trim(), equipment = equipmentCode.Trim() });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {

                if (_LogUtil != null)
                {
                    _LogUtil.Error($"获取托盘空盘实盘类型报错， ex = {ex.Message}");
                    _LogUtil.Error($"获取托盘空盘实盘类型报错， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                headerResult.IsSucceed = false;
                headerResult.Message = "获取托盘空盘实盘类型调用接口异常";
                return headerResult;
            }
        }


        /// <summary>
        /// 获取托盘电芯的信息
        /// </summary>
        /// <returns></returns>
        public static async Task<HeaderResult<ReturnContainer>> GetContainerBatteryAsync(string containerCode, string equipmentCode)
        {

            InterfaceLogInfo interfaceLogInfo = new InterfaceLogInfo();
            HeaderResult<ReturnContainer> headerResult = new HeaderResult<ReturnContainer>();
            try
            {
                interfaceLogInfo.InterfacePara = $"托盘码：{containerCode}；设备号{equipmentCode}；";
                interfaceLogInfo.ActionName = "GetContainerBatteryAsync";
                interfaceLogInfo.StartTime = DateTime.Now;
                interfaceLogInfo.InterfaceUrl = Parameters.GetContainerBatteryAsync;
                interfaceLogInfo.Description = "电芯效验调用WMS获取电芯信息";
                headerResult = await SimpleApiClient.PostAsync<HeaderResult<ReturnContainer>>(Parameters.GetContainerBatteryAsync, new { ContainerBarcode = containerCode.Trim(), EquipmentCode = equipmentCode.Trim() });
                interfaceLogInfo.InterfaceResult = JsonConvert.SerializeObject(headerResult);
                interfaceLogInfo.EndTime = DateTime.Now;
                interfaceLogInfo.IsSuccess = true;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                return headerResult;
            }
            catch (Exception ex)
            {

                if (_LogUtil != null)
                {
                    _LogUtil.Error($"电芯效验调用WMS获取电芯信息， ex = {ex.Message}");
                    _LogUtil.Error($"电芯效验调用WMS获取电芯信息， ex = {ex.StackTrace}");
                }
                if (ex.Message.Contains("at") && ex.Message.Contains("System.Exception:"))
                {

                    var msg = ex.Message.Split("at").First().Split("System.Exception:");
                    interfaceLogInfo.InterfaceResult = msg[1];

                }
                interfaceLogInfo.IsSuccess = false;
                if (_IIterfaceLogInfoService != null)
                    await _IIterfaceLogInfoService.AddInterfaceLogAsync(interfaceLogInfo);
                headerResult.IsSucceed = false;
                headerResult.Message = "调用接口异常";
                return headerResult;
            }
        }

    }
}
